﻿using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.IO;

namespace ConsoleApp_test
{
    public class Program
    {
        public static void Main(string[] args)
        {
            while (true)
            {
                GetUrls().ForEach(WebHelp.GetApi);
                System.Threading.Thread.Sleep(new TimeSpan(0, 5, 0));
            }
        }

        private static IConfigurationRoot GetConfig()
        {
            var builder = new ConfigurationBuilder()
                          //.SetBasePath(AppContext.BaseDirectory)
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile("appsettings.json")
                          .AddEnvironmentVariables();
            return  builder.Build();
        }


        private static List<string> GetUrls()
        {
            var config = GetConfig();
            var result = new List<string>(); 
            for(var i =1; i<=100; i++){
                var url = config["url" + i.ToString()];
                if (!string.IsNullOrWhiteSpace(url))
                    result.Add(url);
            }
            return result;
        }


        //private static List<string> GetUrlsFromFile()
        //{
        //    var path = AppContext.BaseDirectory + "\\urls.txt";

        //    var urls = File.ReadAllLines(path);

        //    return new List<string>(urls);
        //}

    }
}